package com.ztftrue.ble;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

public class Main2Activity extends AppCompatActivity {

    private android.widget.ListView listview;
    private List<BleClass> bleClasses;
    String uuid = "[\n" +
            "        {\n" +
            "            \"uuid\":\"4adbe522-80a6-402f-b64a-68575b046671\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_htl\",\n" +
            "            \"exhibit_name\":\"汉推楼（体验馆）\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"b9eec1e4-1db4-4404-83b5-36b71571f3f3\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_yyt\",\n" +
            "            \"exhibit_name\":\"鸳鸯厅（千年薪传）\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"7fb9ede2-d63c-11e6-bf26-cec0c932ce01\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_xt\",\n" +
            "            \"exhibit_name\":\"西厅（我的博物馆）\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"a48cc9a8-188a-4aa5-aa87-cc1f49ae6f68\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_csl\",\n" +
            "            \"exhibit_name\":\"藏书楼（百年启道）\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"67e2dc89-0d04-45a1-bca2-7ee3ca394a77\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_nmt\",\n" +
            "            \"exhibit_name\":\"楠木厅\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"fd151c5e-f976-4a4a-a2a3-98fb3fc38638\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_qdl\",\n" +
            "            \"exhibit_name\":\"启道楼（时代华章）\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"2acdb9b6-b68b-41e0-a8dd-7196105f9589\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_dt\",\n" +
            "            \"exhibit_name\":\"大厅（杏坛英华）\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"5b3ab32f-7594-43d5-9207-8a0fe30a573c\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_zt\",\n" +
            "            \"exhibit_name\":\"中厅（教化泽被）\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"4baee936-03aa-4209-bdee-dd2b209b14b6\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_mt\",\n" +
            "            \"exhibit_name\":\"门厅\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"uuid\":\"bb6b10e7-ec18-44e7-ace1-ef3f8c58fac3\",\n" +
            "            \"major\":\"10000\",\n" +
            "            \"minor\":\"5000\",\n" +
            "            \"exhibit_id\":\"szjybwg_zx1_cy\",\n" +
            "            \"exhibit_name\":\"柴园\"\n" +
            "        }\n" +
            "    ]";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        this.listview = (ListView) findViewById(R.id.listview);
        Gson gson = new Gson();
        bleClasses = gson.fromJson(uuid, new TypeToken<List<BleClass>>() {
        }.getType());
        listview.setAdapter(new ListAda(this, bleClasses));
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();

                intent.putExtra("uuid", bleClasses.get(position).getUuid());
                intent.putExtra("major", bleClasses.get(position).getMajor());
                intent.putExtra("minor", bleClasses.get(position).getMinor());
                intent.setClass(Main2Activity.this, MainActivity.class);
                startActivity(intent);
            }
        });
    }

}
